package com.liu.OrderService.service.impl;

import com.liu.OrderService.client.EduCourseClient;
import com.liu.OrderService.client.UcenterMemberClient;
import com.liu.OrderService.entity.EduOrder;
import com.liu.OrderService.mapper.EduOrderMapper;
import com.liu.OrderService.service.EduOrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liu.entity.CourseAllInfoVo;
import com.liu.entity.UcenterMember;
import com.liu.utils.OrderNoUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 订单 服务实现类
 * </p>
 *
 * @author LSJ
 * @since 2022-02-11
 */
@Service
public class EduOrderServiceImpl extends ServiceImpl<EduOrderMapper, EduOrder> implements EduOrderService {

    @Autowired
    private  EduCourseClient eduCourseClient;
    @Autowired
    private UcenterMemberClient ucenterMemberClient;

    @Override
    public String createOrder(String courseId, String memberId) {
        EduOrder eduOrder = new EduOrder();
        eduOrder.setCourseId(courseId);

//        远程调用：根据courseId获取课程信息
        CourseAllInfoVo courseAllInfo = eduCourseClient.getCourseAllInfo(courseId);

//        远程调用：根据memberId获取用户信息
        UcenterMember userInfo = ucenterMemberClient.getUserInfoById(memberId);

//        开始将courseAllInfo和userInfo的信息传入eduOrder对象中
        eduOrder.setOrderNo(OrderNoUtil.getOrderNo())
                .setCourseTitle(courseAllInfo.getTitle())
                .setCourseCover(courseAllInfo.getCover())
                .setTeacherName(courseAllInfo.getTeacherName())
                .setTotalFee(courseAllInfo.getPrice())

                .setMemberId(userInfo.getId())
                .setMobile(userInfo.getMobile())
                .setNickname(userInfo.getNickname())
                // 支付状态
                .setStatus(0)
//                支付类型 1：微信，2：支付宝
                .setPayType(1);
         baseMapper.insert(eduOrder);
        return eduOrder.getOrderNo();


    }
}
